package com.go.dp.observer.four;

import java.util.ArrayList;
import java.util.List;

class Child implements Runnable {
	private List<WakenUpListener> listeners = new ArrayList<WakenUpListener>();

	public void addListener(WakenUpListener l) {
		listeners.add(l);
	}

	public void wakeUp() {
		for (WakenUpListener listener : listeners) {
			WakenUpEvent e = new WakenUpEvent(System.currentTimeMillis(),
					"Bad", this);
			listener.actionToWakenUp(e);
		}
	}

	@Override
	public void run() {
		try {
			System.out.println("child sleeping ... ");
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		wakeUp();
	}

}
